package com.cmas.platform.controller;

import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.aidex.common.annotation.DataSource;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.page.TableDataInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.enums.DataSourceType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.common.core.controller.BaseController;
import com.aidex.framework.cache.DictUtils;
import javax.validation.constraints.*;

import com.cmas.platform.domain.em.UserLikeTypeEnum;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.cmas.platform.domain.UserLike;
import com.cmas.platform.service.UserLikeService;


/**
 * 用户点赞表Controller
 * @author su
 * @email 1218819874@qq.com
 * @date 2023-05-03
 */
@DataSource(value = DataSourceType.SLAVE)
@RestController
@RequestMapping("/platform/userLike")
public class UserLikeController extends BaseController  {

    @Autowired
    private UserLikeService userLikeService;

    /**
     * 查询用户点赞表列表
     */
    @PreAuthorize("@ss.hasPermi('platform:userLike:list')")
    @GetMapping("/list")
    public R<TableDataInfo> list(UserLike userLike) {
        startPage();
        List<UserLike> list = userLikeService.selectUserLikeList(userLike);
        return R.data(getDataTable(list));
    }

    /**
     * 获取用户点赞表详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:userLike:query')")
    @GetMapping(value = "/{id}")
    public R<UserLike> detail(@PathVariable("id") String id) {
        return R.data(userLikeService.getById(id));
    }

    /**
     * 新增用户点赞表
     */
    @PreAuthorize("@ss.hasPermi('platform:userLike:add')")
    @Log(title = "用户点赞表", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  UserLike userLike) {
        return R.data(userLikeService.save(userLike));
    }

    /**
     * 修改用户点赞表
     */
    @PreAuthorize("@ss.hasPermi('platform:userLike:edit')")
    @Log(title = "用户点赞表", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated UserLike userLike) {
        return R.data(userLikeService.updateById(userLike));
    }

    /**
     * 删除用户点赞表
     */
    @PreAuthorize("@ss.hasPermi('platform:userLike:remove')")
    @Log(title = "用户点赞表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.data(userLikeService.removeByIds(Arrays.asList(ids)));
    }


    /**
     * 导出用户点赞表列表
     */
    @PreAuthorize("@ss.hasPermi('platform:userLike:export')")
    @Log(title = "用户点赞表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(UserLike userLike) {
        List<UserLike> list = userLikeService.selectUserLikeList(userLike);
        ExcelUtil<UserLike> util = new ExcelUtil<UserLike>(UserLike.class);
        return util.exportExcel(list, "用户点赞表数据");
    }
	
    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

    // ***用户系统位置戳****

    /**
     * 用户点赞帖子
     * @return
     */
    @PostMapping("/userLikePost")
    public R<?> userLikePost(@RequestBody UserLike userLike){
        return R.data(userLikeService.userLike(userLike,UserLikeTypeEnum.POST.getValue()));
    }


    /**
     * 用户点赞评论
     * @return
     */
    @PostMapping("/userLikeComment")
    public R<?> userLikeComment(@RequestBody UserLike userLike){
        return R.data(userLikeService.userLike(userLike,UserLikeTypeEnum.COMMENT.getValue()));
    }


}
